perf: memoize field row containers #6189
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Currently we have a lot of unnecessary re-renders on our Build and Design Content. Many components are re-rendering despite no changes to their properties. This is caused by the large number of hooks we use in the component.
This causes extreme lag in large forms as the re-renders linearly increments the page rendering time for every single action (dragging, selecting, modifying fields in the admin-form view)
This is especially detrimental for dragging fields, as it can cause the admin view for large forms to be almost impossible to navigate.
Closes #6121
Solution
Move out some of the hooks from
FieldRowContainer
to its parentBuilderField
which are causing most of the unnecessary re-rendersUse react memo to memoize the
FieldRowContainer
with deep comparison of props.Breaking Changes
Before & After Screenshots
BEFORE:
Large amount of re-render time as seen in the right.
Screen.Recording.2023-04-25.at.1.16.24.PM.mov
AFTER:
Screen.Recording.2023-04-25.at.1.15.14.PM.mov
Tests
To ensure the feature works
Use react dev tool -> profiler
Go to a large form
To ensure core features are still intact
Notes
There are still a few unnecessary re-renders upon drag and dropping of the fields.
Ideally, only the fields affected (field id changed) should re-render and all other fields should be unaffected. However, currently there is still some existing hooks that causes a re-render for all the fields even if they are memoized